package com.qiaofang.applet.rest;

import com.qiaofang.applet.common.dto.DataRequest;
import com.qiaofang.applet.common.dto.DataResponse;
import com.qiaofang.applet.common.dto.PageDataRequest;
import com.qiaofang.applet.common.util.PageUtil;
import com.qiaofang.applet.service.member.service.*;
import com.qiaofang.applet.service.member.service.dto.*;
import com.qiaofang.applet.service.other.service.dto.AutoEmployeeReplyDto;
import com.qiaofang.applet.service.property.service.dto.IdDto;
import com.qiaofang.applet.service.property.service.dto.UniqueUuidDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author daiyuxaing
 */
@Slf4j
@RestController
@RequestMapping("/api/web/auth/memberOperate")
@Api(tags = "会员：会员操作记录")
public class MemberOperateController {

    @Autowired
    private MemberService membeService;

    @Autowired
    private MemberShareService memberShareService;

    @Autowired
    private MemberExploreService memberExploreService;

    @Autowired
    private MemberExchangeService memberExchangeService;

    @Autowired
    private MemberOperateService memberOperateService;

    @PostMapping("/addShare")
    @ApiOperation(value = "添加分享记录", notes = "添加分享记录")
    public DataResponse<String> addShare(@RequestBody @Valid DataRequest<MemberShareAddDto> request) {
        return DataResponse.ok(memberShareService.addShareRecord(request.getParam()));
    }

    @PostMapping("/getShareNodeInfo")
    @ApiOperation(value = "获取分享节点信息", notes = "获取分享节点信息")
    public DataResponse<MemberShareGetDto> getShareNodeInfo(@RequestBody @Valid DataRequest<IdDto> request) {
        return DataResponse.ok(memberShareService.getShareNodeInfo(request.getParam().getId()));
    }

    @PostMapping("/addExplore")
    @ApiOperation(value = "添加浏览记录", notes = "添加浏览记录")
    public DataResponse<String> addExplore(@RequestBody @Valid DataRequest<MemberExploreAddDto> request) {
        return DataResponse.ok(memberExploreService.addExploreRecord(request.getParam()));
    }

    @PostMapping("/setExploreDuration")
    @ApiOperation(value = "保存浏览时长", notes = "保存浏览时长")
    public DataResponse<Object> setExploreDuration(@RequestBody @Valid DataRequest<IdDto> request) {
        memberExploreService.setExploreDuration(request.getParam().getId());
        return DataResponse.ok();
    }

    @PostMapping("/addInteractiveRecords")
    @ApiOperation(value = "添加聊天、电话记录", notes = "添加聊天、电话记录")
    public DataResponse<Object> addInteractiveRecords(@RequestBody @Valid DataRequest<MemberExchangeAddDto> request) {
        memberExchangeService.addExchangeRecord(request.getParam());
        return DataResponse.ok();
    }

    @PostMapping("/getIndexFollowersAndVisitors")
    @ApiOperation(value = "个人门店头部数据-近30日访客、粉丝、关注", notes = "个人门店-近30日访客、粉丝、关注")
    public DataResponse<FollowersAndVisitorsDto> getIndexFollowersAndVisitors(@RequestBody @Valid DataRequest<AutoEmployeeReplyDto> request) {
        return DataResponse.ok(memberOperateService.getIndexFollowersAndVisitors(request.getParam().getUniqueUuid(), request.getParam().getMemberId()));
    }

    @PostMapping("/getDailyData")
    @ApiOperation(value = "个人门店-今日数据", notes = "个人门店-今日数据")
    public DataResponse<DailyDataDto> getDailyData(@RequestBody @Valid DataRequest<DailyDataQueryDto> request) {
        return DataResponse.ok(memberOperateService.getDailyData(request.getParam()));
    }

    @PostMapping("/getDailyDataForVisit")
    @ApiOperation(value = "数据-今日访问数据", notes = "数据-今日访问数据")
    public DataResponse<DailyDataForVisitDto> getDailyDataForVisit(@RequestBody @Valid DataRequest<DailyDataQueryDto> request) {
        return DataResponse.ok(memberOperateService.getDailyDataForVisit(request.getParam()));
    }

    @PostMapping("/getDailyDataForForward")
    @ApiOperation(value = "数据-今日转发数据", notes = "数据-今日转发数据")
    public DataResponse<DailyDataForForwardDto> getDailyDataForForward(@RequestBody @Valid DataRequest<DailyDataQueryDto> request) {
        return DataResponse.ok(memberOperateService.getDailyDataForForward(request.getParam()));
    }

    @PostMapping("/getDailyDataForExchange")
    @ApiOperation(value = "数据-今日互动数据", notes = "数据-今日互动数据")
    public DataResponse<DailyDataForExchangeDto> getDailyDataForExchange(@RequestBody @Valid DataRequest<DailyDataQueryDto> request) {
        return DataResponse.ok(memberOperateService.getDailyDataForExchange(request.getParam()));
    }

    @PostMapping("/getMemberBrowseTracks")
    @ApiOperation(value = "当前会员浏览轨迹", notes = "当前会员浏览轨迹")
    public DataResponse<Page<MemberBrowseTracksDto>> getMemberBrowseTracks(@RequestBody @Valid PageDataRequest<DailyDataQueryDto> request) {
        return DataResponse.ok(memberOperateService.getMemberBrowseTracks(request.getParam(), PageUtil.getPageable(request)));
    }

    @PostMapping("/updateMemberRemark")
    @ApiOperation(value = "修改会员备注", notes = "修改会员备注")
    public DataResponse<Object> updateMemberRemark(@RequestBody @Valid DataRequest<UpdateMemberRemarkDto> request) {
        return DataResponse.ok(memberOperateService.updateMemberRemark(request.getParam()));
    }

    @PostMapping("/getMemberShareTrack")
    @ApiOperation(value = "当前会员分享轨迹", notes = "当前会员分享轨迹")
    public DataResponse<List<MemberShareTracksDto>> getMemberShareTrack(@RequestBody @Valid DataRequest<DailyDataQueryDto> request) {
        return DataResponse.ok(memberOperateService.getMemberShareTrack(request.getParam()));
    }


    @PostMapping("/getVisitorList")
    @ApiOperation(value = "访客列表（客源管理页）", notes = "访客列表（客源管理页）")
    public DataResponse<Page<CustomerManageDto>> getVisitorList(@RequestBody @Valid PageDataRequest<UniqueUuidDto> request) {
        return DataResponse.ok(memberOperateService.getVisitorList(request.getParam().getUniqueUuid(), PageUtil.getPageable(request)));
    }

    @PostMapping("/getFansList")
    @ApiOperation(value = "粉丝列表（客源管理页）", notes = "粉丝列表（客源管理页）")
    public DataResponse<Page<CustomerManageDto>> getFansList(@RequestBody @Valid PageDataRequest<UniqueUuidDto> request) {
        return DataResponse.ok(memberOperateService.getFansList(request.getParam().getUniqueUuid(), PageUtil.getPageable(request)));
    }

    @PostMapping("/getFocusList")
    @ApiOperation(value = "关注列表（客源管理页）", notes = "关注列表（客源管理页）")
    public DataResponse<Page<CustomerManageDto>> getFocusList(@RequestBody @Valid PageDataRequest<UniqueUuidDto> request) {
        return DataResponse.ok(memberOperateService.getFocusList(request.getParam().getUniqueUuid(), PageUtil.getPageable(request)));
    }

    @PostMapping("/getEmpMemberDetail")
    @ApiOperation(value = "经纪人客户互动详情", notes = "经纪人客户互动详情")
    public DataResponse<CustomerManageDto> getEmpMemberDetail(@RequestBody @Valid DataRequest<EmpMemberDetailDto> request) {
        return DataResponse.ok(memberOperateService.getEmpMemberDetail(request.getParam()));
    }
}
